package com.RLFZ.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.RLFZ.entity.User;
import com.RLFZ.mapper.RoleMapper;
import com.RLFZ.mapper.UserMapper;
import com.RLFZ.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务接口实现
 *
 * @author zh
 * @since 2022-08-25 17:16:58
 * @description 
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public User login(String username, String password) {
        return userMapper.login(username,password);
    }

    @Override
    public void saveUserRole(Integer uid, Integer[] ids) {
        roleMapper.deleteRoleUserByUid(uid);
        if (ids!=null&&ids.length>0){
            for (Integer rid : ids){
                roleMapper.saveUserRole(uid,rid);
            }
        }
    }

    @Override
    public List select(String username) {
        return null;
    }
}